#include <pthread.h>

class lock_gurad {
public:
    lock_gurad(pthread_mutex_t *lock) :_lock(lock) {
        pthread_mutex_lock(_lock);
    }
    ~lock_gurad() {
        pthread_mutex_unlock(_lock);
    }
private:
    pthread_mutex_t *_lock;
};